let endPoint = JSON.stringify({  //终点
  'name': '吉野家(北京西站北口店)',
  'latitude': 39.89631551,
  'longitude': 116.323459711
});


Page({
  data: {
    active: 0,
    // option1: [
    //   { text: '分公司', value: 0 },
    //   { text: '公司1', value: 1 },
    //   { text: '公司2', value: 2 },
    // ],
    // option2: [
    //   { text: '切果品', value: 'a' },
    //   { text: '果品1', value: 'b' },
    //   { text: '果品2', value: 'c' },
    // ],
    companyArray: ['公司1', '公司2'],
    selCompany: {
      companyName: '切分公司'
    },
    selete2Arr: ['苹果'],
    selete2Name: '切果品',
    // value1: 0,
    // value2: 'a',
    tabactive: 'task',
    list: [],
    activeNames: ['a', 'a'],
    showD: false,
    active1: 'dispatch',
    mapType: 'dt',
    mapScale: 14,
    latitude: 39.865021,
    longitude: 116.379019,
    polyline: [],

    markers: [
      {
        id: 0
        , iconPath: "/assets/img/dispatch/map_car2.png"
        , longitude: 116.379019
        , latitude: 39.865021
        , width: 30
        , height: 30
      }
    ],
    canScale: false,
    show_mudi: false,
    points: [
      {
        name: '待启动',
        zhuangzai: 30,
        desc: {
          title: '起点名',
          title: '站长名',
          phone: '18025600059'
        },
        poi: {
          latitude: 32,
          longitude: 116,
          address: '广州'
        },
        chufa: {
          shiji: ' 02.08 19:00',
          yugu: ' 02.18 20:00'
        }, daoda: {
          shiji: '2024.02.08 19:00',
          yugu: '2024.02.18 20:00'
        }
      },
      {
        name: '正常',
        zhuangzai: 30,
        desc: {
          title: 'A点',
          title: '站长名',
          phone: '18025600059'
        },
        poi: {
          latitude: 32,
          longitude: 116,
          address: '广州'
        },
        chufa: {
          shiji: '02.08 19:01',
          yugu: '02.18 20:00'
        }, 
        daoda: {
          shiji: '2024.02.08 19:00',
          yugu: '2024.02.18 20:00'
        }
      },
      {
        name: '超时',
        zhuangzai: 30,
        desc: {
          title: 'B点',
          title: '站长名',
          phone: '18025600059'
        },
        poi: {
          latitude: 32,
          longitude: 116,
          address: '广州'
        },
        chufa: {
          shiji: '2024.02.08 19:00',
          yugu: '2024.02.18 20:00'
        }, daoda: {
          shiji: '2024.02.08 19:00',
          yugu: '2024.02.18 20:00'
        }
      }],
  },
  onChange(event) {
    // wx.showToast({
    //   title: `切换到标签 ${event.detail.name}`,
    //   icon: 'none',
    // });
  },
 
  sijiGuiJi: function (e) {

    let polylinelist  = [ {
  points: [{
    longitude: 116.379019,
    latitude: 39.865021
  },
  {
    longitude: 115.979019,
    latitude: 37.865021
  },
  {
    longitude: 114.979019,
    latitude: 37.865021
  }, {
    longitude: 112.64820869,
    latitude: 28.08330837
  }
  ],
  color: "#3ea2e0",
  width: 8,
  dottedLine: false
}]
let polylinemak = [
  {
    id: 0
    , iconPath: "/assets/img/dispatch/map_car2.png"
    , longitude: 116.379019
    , latitude: 39.865021
    , width: 30
    , height: 30
  },
  {
    id: 1
    ,iconPath: "/assets/img/dispatch/map_car3.png"
    , longitude: 112.64820869 
    ,latitude: 28.08330837
    ,width: 20
    ,height: 20
    }
]
this.setData({
  polyline: polylinelist,
  markers:polylinemak,
  show_mudi:true
})
   
  },
  phoneCall: function (e) {
    wx.makePhoneCall({
      phoneNumber: e.currentTarget.dataset.replyPhone,
      success: function () {
 this.setData({
      tabactive: e.target.dataset.self,

    })
      },
    })
  },
  //  任务分派 （创建任务）
  createLongRW: function (e) {
    console.log("任务分派 （创建任务）")
    wx.navigateTo({
      url: '/packageDispatch/pages/mine/createLong/index',
      success: function(res) {
        // 通过eventChannel向被打开页面传送数据
        res.eventChannel.emit('acceptDataFromOpenerPage', { data: 'test' })
      }
    })
  },
  onLoad() {
    this.getList()
  },

  //map
  fetchShopDetail(e){
    console.log('fetchShopDetail',e);
  },
  getList() {
    let list = []
    for (let index = 0; index < 5; index++) {
      const element = {
        id: index,
        name: '西瓜' + index
      };
      list.push(element)
    }
    console.log(list);
    this.setData({
      list: list
    })
    setTimeout(() => {
      wx.hideLoading()
    }, 700)
  },
  changeTab(e) {
    this.setData({
      tabactive: e.target.dataset.self,

    })

    // wx.showLoading()
    this.setData({
      list: []
    })
    // this.getList()
  },
  point_open(event) {
    this.setData({
      showD: true
    });
  },
  changeMapypeTab(event) {
    this.setData({
      mapType: event.target.dataset.self,
      mapScale: 14,
      canScale: true
    })
  },
  onChange(event) {

    switch (event.detail) {
      case 'tongji':
        wx.redirectTo({
          url: '/pages/dispatch/tongji/index'
        });
        break;
      case 'order':
        wx.redirectTo({
          url: '/pages/dispatch/order/index'
        });
        break;
      case 'dispatch':
        wx.redirectTo({
          url: '/pages/dispatch/dispatchManage/index/index'
        });
        break;
      case 'receive':
        wx.redirectTo({
          url: '/pages/dispatch/receive/index/index'
        });
        break;
      case 'mine':
        wx.redirectTo({
          url: '/pages/dispatch/mine/index/index'
        });
        break;
    }
    this.setData({ active1: event.detail });

  },
  onDingWei(event) {
    let polylinemak2 = [
      {
        id: 0
        , iconPath: "/assets/img/dispatch/map_car2.png"
        , longitude: 116.379019
        , latitude: 39.865021
        , width: 30
        , height: 30
      },
      {
        id: 1
        ,iconPath: "/assets/img/dispatch/map_car3.png"
        , longitude: 112.64820869 
        ,latitude: 28.08330837
        ,width: 20
        ,height: 20
        },
        {
          id: 333
          , iconPath: "/assets/img/dispatch/map_car4.png"
          , longitude: 115.979019
          , latitude: 37.865021
          , width: 30
          , height: 30
        }
    ]
    // let newarray = [{
    //   id: 3
    //   , iconPath: "/assets/img/dispatch/map_car4.png"
    //   , longitude: 115.979019
    //   , latitude: 37.865021
    //   , width: 30
    //   , height: 30
    // }]
    // longitude: 115.979019,
    // latitude: 37.865021
    this.data.markers = polylinemak2
    this.setData({
      // markers: this.data.markers.concat(newarray),
      markers:polylinemak2,
      longitude: 115.979019,
      latitude: 37.865021,
      mapScale: 10
    });
  },
  changeMapypeTab2(event) {
    this.setData({
      mapType: event.target.dataset.self,
      mapScale: 3,
      canScale: true
    })
  }
});
